package me.goldze.mvvmhabit.binding.viewadapter.recyclerview

import android.content.Context
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.luck.picture.lib.decoration.WrapContentLinearLayoutManager

object LayoutManagers {
    @JvmStatic
    @JvmOverloads
    fun linearVertical(context: Context, parentIsScroll: Boolean = false): LinearLayoutManager {
        return if (parentIsScroll) object : WrapContentLinearLayoutManager(context, RecyclerView.VERTICAL, false) {
            override fun canScrollVertically(): Boolean {
                return false
            }
        }
        else WrapContentLinearLayoutManager(context, RecyclerView.VERTICAL, false)
    }

    @JvmStatic
    @JvmOverloads
    fun linearHorizontal(context: Context, parentIsScroll: Boolean = false): LinearLayoutManager {
        return if (parentIsScroll) object : WrapContentLinearLayoutManager(context, RecyclerView.HORIZONTAL, false) {
            override fun canScrollHorizontally(): Boolean {
                return false
            }
        }
        else WrapContentLinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
    }

    @JvmStatic
    @JvmOverloads
    fun gridVertical(context: Context, spanCount: Int, parentIsScroll: Boolean = false): GridLayoutManager {
        return if (parentIsScroll) object : GridLayoutManager(context, spanCount, RecyclerView.VERTICAL, false) {
            override fun canScrollVertically(): Boolean {
                return false
            }
        }
        else GridLayoutManager(context, spanCount, RecyclerView.VERTICAL, false)
    }

    @JvmStatic
    @JvmOverloads
    fun gridHorizontal(context: Context, spanCount: Int, parentIsScroll: Boolean = false): GridLayoutManager {
        return if (parentIsScroll) object : GridLayoutManager(context, spanCount, RecyclerView.HORIZONTAL, false) {
            override fun canScrollVertically(): Boolean {
                return false
            }
        }
        else GridLayoutManager(context, spanCount, RecyclerView.HORIZONTAL, false)
    }
}